#include <iostream>
using namespace std;
int Eular(int n)
{
    int eu = n;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            eu -= eu / i;
            while (n % i == 0)
                n /= i;
        }
    }
    if (n > 1) // n本身也是个质因子
        eu -= eu / n;
    return eu;
}
int main(int argc, char const *argv[])
{
    int p;
    while (cin >> p)
    {
        cout << Eular(p - 1) << endl;
    }
    return 0;
}
